<?php
// import item base
Magnum::import('utility/stack/item');
/**
 * css stacks
 * @uses Magnum_Utility_Stack_Item
 */
class Magnum_Head_Css extends Magnum_Utility_Stack_Item
{
    // only change to constructor: name
    public function __construct()
    {
        parent::__construct('__css');

    }// end __construct


    /**
     * add css
     * @param str $css the css
     * @param str $media the media
     * @param str $type the type
     * @return $this
     */
    public function set($css, $media = 'screen', $type = 'OVERWRITE')
    {
        // add to stack
        return parent::_set($this->_getMarkup($css, $media), null, $type);

    }// end add


    /**
     * append css
     * @param str $css the css
     * @param str $media the media
     * @param str $key the key to set the css at, default null
     * @return $this
     */
    public function append($css, $media = 'screen', $key = null)
    {
        return parent::_append($this->_getMarkup($css, $media), $key);

    }// end append


    /**
     * prepend css
     * @param str $css the css
     * @param str $media the media
     * @param str $key the key to set the css at, default null
     * @return $this
     */
    public function prepend($css, $media = 'screen', $key = null)
    {
        return parent::_prepend($this->_getMarkup($css, $media), $key);

    }// end prepend

    /**
     * get css markup
     */
    public function _getMarkup($css, $media)
    {
        // smart check...
        if (strpos($css, '{') !== false) {
            $item = '<style type="text/css" media="' . $media . '"><!--' . EOL . $css . EOL . '--></style>';
        } else {
            $item = '<link rel="stylesheet" href="' . $css . '" type="text/css" media="' . $media . '" />';
        }

        return $item;

    }// end _getMarkup

}// end Magnum_Head_Css
?>